﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Client;
using Common.Types;
using Common.Utils;

namespace Places
{
    public class Service
    {
        public static readonly Uri ApiUrl =
            new Uri("https://maps.googleapis.com/maps/api/place/search/");

        public readonly string APIKey;

        public Service(string apiKey)
        {
            APIKey = apiKey;
        }

        /// <summary>
        /// Sends the specified request to the Google Maps Places web
        /// service and parses the response as an GeocodingResponse
        /// object.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PlacesResponse GetResponse(PlacesRequest request)
        {
            var url = new Uri(ApiUrl, UrlBuilder.ToUri(request));
            return HttpClient.Get(url).As<PlacesResponse>();
        }
    }
}
